<?
	include("../main_inc.php");
	
	if($_GET['id']) $id=$_GET['id'];
	elseif ($_POST['id']) $id=$_POST['id'];

?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Bubble Affiliate Program</title>

<link href="../../css/admin.css" rel="stylesheet" type="text/css">
<script src="../../jscript/menuArrayAffiliate.php" language="javascript"></script>
<script src="../../jscript/clock.js" language="javascript"></script>
<script>
	var CText=Array();
	<?php
	$Count=0;
	$r=new ReturnRecord();
	$sq2=$r->rawQuery("SELECT id,BType,HTMLCode,Image FROM affiliateBanners WHERE affiliateProgramsID=$id");  
	while ($myrow = mysql_fetch_row($sq2)) {
		if($myrow[1]=="Image"){
			?>CText[<?=$myrow[0]?>]='<img src="<?=$rootdir?>banners/<?=$myrow[3]?>">';<?
		}else{
			?>CText[<?=$myrow[0]?>]='<?=$myrow[2]?>';<?
		};
	}
?>
    
	
	
	function GetCode(Domain,Banner){
		var ExtraCode="<script src='http://<?=$host.$rootdir;?>codes/banner.php?ab=";
		ExtraCode+=Banner+"&aid=<?=$_SESSION['AffKey'];?>&d="+Domain+"'";
		ExtraCode+=" type='text/javascript'><\/script>";
		return ExtraCode;
	}
	
	function SetCodes(){
		var CType=document.getElementById("CType").value;
		var Domain=document.getElementById("domainID").value;
		
		
		if(Domain>0){
			if(CType>0){
				var Target=document.getElementById("PreviewSpan");
				Target.innerHTML=CText[CType];
				var Target=document.getElementById("CopyCode");
				Target.value=GetCode(Domain,CType);
			}else{
				
				var Target=document.getElementById("CopyCode");
				Target.value="Please Select Code Type";
			}
		}else{
			
			var Target=document.getElementById("CopyCode");
			Target.value="Please Select A Domain";
		}
		
	}
</script>

</head>

<body onLoad="funClock();">
<?php include("../header.php"); ?>
<table width="100%" border="0" cellspacing="25" cellpadding="0">
<tr>
<td valign="top" width="240"><div id="menu"><?php include("../menu.php"); ?></div></td>
<td valign="top" align="center">


  <div id="titleCompact">Get Codes </div>
  <div id="contentCompact">
    <table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#E9EEF5">
      <tr id="formHeader">
        <td><strong>Select Advertisement from drop down box </strong><strong></strong></td>
      </tr>
      <tr>
        <td align="center" bgcolor="#FFFFFF"><table width="400" border="0" cellspacing="0" cellpadding="4">
          <tr>
            <td height="30">Domain</td>
            <td><select name="domainID" class="formFields" id="domainID" onChange="SetCodes();">
              <option value="0">-Please Select Domain</option>
              <?php
					$sq2=$r->rawQuery("SELECT id,domain FROM affiliateDomains WHERE affiliateID=$_SESSION[AffKey] AND Active='Yes'");  
					while ($myrow = mysql_fetch_row($sq2)) {
						echo"<option value='$myrow[0]'>$myrow[1]</option>";
					};
				?>
            </select></td>
          </tr>
          <tr>
            <td width="130" height="30">Advertisement:</td>
            <td width="354"><select name="CType" id="CType" class="formFields" onChange="SetCodes();">
              <option value="0">-Please Select Ad Type</option>
			  <?php
					$sq2=$r->rawQuery("SELECT id,Name FROM affiliateBanners WHERE affiliateProgramsID=$id");  
					while ($myrow = mysql_fetch_row($sq2)) {
						echo"<option value='$myrow[0]'>$myrow[1]</option>";
					};
				?>          
            </select>            </td>
          </tr>

        </table></td>
      </tr>
    </table>
    <br>
    <br>
    <table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#E9EEF5">
      <tr id="formHeader">
        <td><strong>Preview</strong><strong></strong></td>
      </tr>
      <tr>
        <td align="center" bgcolor="#FFFFFF"><span id="PreviewSpan"></span></td>
      </tr>
    </table>
  </div>


  <br>
  <div id="contentCompact"></div>
  <br>
  <div id="contentCompact">
    <table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#E9EEF5">
      <tr id="formHeader">
        <td><strong>Copy Code  </strong><strong></strong></td>
      </tr>
      <tr>
        <td align="center" bgcolor="#FFFFFF"><textarea name="CopyCode" cols="70" rows="8" class="formFields" id="CopyCode">Please Select Domain and Advertisement</textarea></td>
      </tr>
    </table>
  </div></td>
</tr>
</table>
</body>
</html>
